<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>五指山污水处理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/css/public.css" media="all">
    <link rel="shortcut icon" href="<%=request.getContextPath()%>/huazhi/images/favicon.ico"/>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card">
            <div class="layui-card-body">
                <blockquote class="layui-elem-quote">
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <input class="layui-input searchval" type="text" placeholder="请输入搜索的内容">
                        </div>
                        <button class="layui-btn" id="search_btn" data-type="reload">搜索</button>
                    </div>
                </blockquote>
                <table class="layui-hide" id="chemicalTable" lay-filter="chemicalTables"></table>
                <div id="laypage"></div>
            </div>
        </div>
    </div>
</div>
<input type="hidden" id="curnum" value="1">
<script type="text/html" id="chemicalOperation">
    <div class="layui-inline" lay-event="add" title="添加">
        <i class="layui-icon layui-icon-add-1"></i>
    </div>
</script>
<script type="text/html" id="table-chemical">
    <a class="layui-btn layui-btn-xs layui-btn-primary"  lay-event="info">详情</a>
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="update">修改</a>
<%--    {{# if(d.isbinding == '0'){}}--%>
<%--    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="binding">绑定</a>--%>
<%--    {{# }else if (d.isbinding != '0'){}}--%>
<%--    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="unbound">解绑</a>--%>
<%--    {{# }}}--%>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script src="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/layui.all.js"></script>
<script src="<%=request.getContextPath()%>/huazhi/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['table', 'user', 'layer', 'form', ], function () {
        var $ = layui.jquery,
            table = layui.table,
            dtree = layui.dtree,
            layer = layui.layer,
            form = layui.form
           , laypage = layui.laypage

        var limitcount = 10;

        //搜索事件
        var active = {
            reload: function () {  //data-type='reload'
                var searchval = $('.searchval').val();
                $("#curnum").val("1");
                table.reload('chemicalTable', { //表格的id
                    where: {
                        key: searchval,
                        page: 1,
                        limit: 10,
                    },
                    text: {
                        none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                    }
                })
            }
        };

        $('#search_btn').on('click', function () { //搜索的id
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        table.render({
            elem: '#chemicalTable'
            , url:  "<%=request.getContextPath()%>/rest/base/getwxssList"
            , toolbar: '#chemicalOperation'
            , height: 'full-200'
            , title: '巡检巡查'
            , defaultToolbar: ['filter', 'print']
            , cols: [[
                {title: 'ID', width: 70, sort: true, fixed: 'left', type: 'numbers'},
                {field: 'czmc', title: '所在自然村', sort: true},
                {field: 'ssbm', title: '设备编码', sort: true},
                {field: 'wxrqSting', title: '维修日期', sort: true},
                {field: 'wxhzk', title: '维修后状况', sort: true},
                {field: 'wxlsry', title: '维修落实人员', sort: true},
                {title: '操作', toolbar: '#table-chemical', align: "center", width: 250, fixed: "right"}]]
            , page: false
            , limit: limitcount
            , text: {
                none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            },
            // limits:[10, 20, 30, 40, 50],
            done: function (res, curr, count) {
                if (res.errorMsg == null) {

                } else {
                    layer.msg(res.errorMsg);
                }
                var curnum = $("#curnum").val();
                $('.layui-table-fixed-r').removeClass('layui-hide');//列固定右侧
                laypage.render({
                    elem: 'laypage'
                    , first: '首页'
                    , last: '尾页'
                    , groups: 5
                    , count: count
                    , curr: curnum
                    , limit: limitcount
                    , layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
                    , limits: [10, 15, 20]
                    , jump: function (obj, first) {
                        if (!first) {
                            curnum = obj.curr;
                            $("#curnum").val(curnum)
                            limitcount = obj.limit;
                            table.reload('chemicalTable', { //表格的id
                                where: {
                                    page: curnum,
                                    limit: limitcount
                                }
                            })

                        }
                    }
                })
            }
        })


        //监听工具条
        table.on('tool(chemicalTables)', function (obj) {  //表格的lay-filter="userlists"
            var data = obj.data; //获得当前行所有数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if (obj.event === 'del') {
                deletes(data, obj);
            } else if (obj.event === 'update') {
                update(data);
            }else  if(obj.event === 'info'){
                info(data)
            }
        });

        function deletes(data, obj) {
            layer.confirm('确定删除此数据', {icon: 3, title: '提示信息'}, function (index) {
                var index = layer.msg('删除中，请稍候', {icon: 16, time: false, shade: 0.6});
                setTimeout(function () {
                    //向服务端发送删除指令
                    $.ajax({
                        type: "post",
                        url:  "<%=request.getContextPath()%>/rest/base/delWxssById",
                        data: "id=" + data.id,
                        dataType: "json",
                        async: false,
                        success: function (msg) {
                            layer.close(index);
                            if (msg === true) {
                                layer.msg('删除成功');
                                obj.del();
                            } else {
                                layer.msg(msg.errorMsg);
                            }
                        }
                    })
                }, 2000);
            });
        }

        function update(data) {
            var clocess = "1";
            layer.open({
                title: "修改",
                type: 2,
                content:  '<%=request.getContextPath()%>/rest/getRoute?type=instrument&url=wxss_update',
                //是否显示右上角关闭图标，默认为1，显示
                area: ['90%', '91%'],
                maxmin: true,
                shade: 0.6,
                anim: 4,
                skin: 'layui-layer-molv',
                resize: true,
                success: function (layero, index) {  //当你需要在层创建完毕时即执行一些语句，可以通过该回调 想相当于吧值转到子界面
                    var iframe = window['layui-layer-iframe' + index];
                    iframe.child(data.id)
                }, cancel: function (index, layero) {
                    layer.close(index)
                    clocess = "2"
                    return false;
                },
                end: function () {
                    if (clocess !== "2") {
                        table.reload('chemicalTable')
                    }
                    return false;
                }
            });
        }

        function info(data) {
            layer.open({
                title: "详情",
                type: 2,
                content: '<%=request.getContextPath()%>/rest/getRoute?type=instrument&url=wxss_info',
                //是否显示右上角关闭图标，默认为1，显示
                area: ['90%', '91%'],
                maxmin: true,
                shade: 0.6,
                anim: 4,
                skin: 'layui-layer-molv',
                resize: true,
                success: function (layero, index) {  //当你需要在层创建完毕时即执行一些语句，可以通过该回调 想相当于吧值转到子界面
                    var iframe = window['layui-layer-iframe' + index];
                    iframe.child(data.id)
                }
            });
        }

        table.on('toolbar(chemicalTables)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id)
                , data = checkStatus.data, //获取选中的数据
                newsId = [];
            switch (obj.event) {
                case 'add':
                    var clocess = "1";
                    var index = layer.open({
                        title: "添加",
                        type: 2,
                        content: '<%=request.getContextPath()%>/rest/getRoute?type=instrument&url=wxss_add',
                        maxmin: true,
                        area: ['90%', '91%'],
                        //是否显示右上角关闭图标，默认为1，显示
                        anim: 4,
                        shade: 0.6,
                        skin: 'layui-layer-molv',
                        resize: true,
                        cancel: function (index, layero) {
                            layer.close(index)
                            clocess = "2"
                            return false;
                        },
                        success: function (layero, index) {  //当你需要在层创建完毕时即执行一些语句，可以通过该回调 想相当于吧值转到子界面
                            var body = layer.getChildFrame('body', index);//建立父子联系  //当你试图在当前页获取iframe页的DOM元素时，你可以用此方法。

                        },
                        end: function () {
                            if (clocess !== "2") {
                                table.reload('chemicalTable')
                            }
                            return false;
                        }
                    });
//                    $('.layui-layer-setwin .layui-layer-max').css("display", "none")
//                    $('.layui-layer-setwin .layui-layer-min').css("display", "none")
                    break;
            }
        });
    });
</script>
</body>
</html>
